
Partial Class ReportPage
    Inherits System.Web.UI.Page

    Dim reportCol As Collection

    Private summaryHeight As Integer = 0
    Private injuriesHeight As Integer = 0
    Private trainingsHeight As Integer = 0
    Private playersHeight As Integer = 0
    Private seasonsHeight As Integer = 0

    Private rId As Integer
    Private sId As Integer
    Private uId As Integer



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        

        If (Not Page.IsPostBack) Then
            rId = CInt(Request.Params.Item("rId").ToString)
            sId = CInt(Request.Params.Item("sId").ToString)
            uId = CInt(Request.Params.Item("uId").ToString)

            ViewState.Add("rid", rId)
            ViewState.Add("sid", sId)
            ViewState.Add("uid", uId)

            'LoadRptsDDLForSimulation(sId)
            LoadReports(rId)
        End If
        If (Not Session.Item(ViewState.Item("uid").ToString) = ViewState.Item("uid")) Then
            Response.Redirect("Welcome.aspx")
        End If


    End Sub

    Private Sub LoadReports(ByVal rId As Integer)
        
        Dim eng As PrivateEngine = Utility.DeSerialize(Server.MapPath("~/App_Data/"), rId)

        PopulateSummary(eng)
        PopulateInjuries(eng)
        PopulateTrainings(eng)
        PopulatePlayers(eng)

    End Sub

    Private Function PopulateSummary(ByVal eng As PrivateEngine) As Boolean

        summarydiv.Controls.Clear()

        Dim container As New Table
        container.GridLines = GridLines.Both
        container.CellPadding = 20
        Dim row1 As New TableRow
        row1.VerticalAlign = VerticalAlign.Top
        Dim cell1 As New TableCell
        Dim cell2 As New TableCell
        Dim cell3 As New TableCell

        'training table part
        BuildTable1(eng, "selTrainingsTable", eng.SelectedTrainingsCol, cell1)

        'injury table part
        BuildTable2("selInjuriesTable", eng.SelectedInjuriesCol, "Injuries", cell2)

        'players table part
        BuildTable2("selPlayersTable", eng.SelectedPlayersCol, "Players", cell3)


        row1.Cells.Add(cell1)
        row1.Cells.Add(cell2)
        row1.Cells.Add(cell3)
        container.Rows.Add(row1)


        summarydiv.Controls.Add(container)

        Return True

    End Function

    Private Function BuildTable1(ByVal eng As PrivateEngine, ByVal tableName As String, ByVal col As Collection, ByVal cell As TableCell) As Boolean

        Dim table As New Table
        table.GridLines = GridLines.Both
        table.ID = tableName
        Dim headerRow As New TableRow
        headerRow.BackColor = Drawing.Color.Beige
        Dim headerCell1 As New TableCell
        headerCell1.Text = "Season"
        headerCell1.Font.Bold = True
        Dim headerCell2 As New TableCell
        headerCell2.Text = "Trainings"
        headerCell2.Font.Bold = True

        headerRow.Cells.Add(headerCell1)
        headerRow.Cells.Add(headerCell2)

        table.Rows.Add(headerRow)

        For indx As Integer = 1 To col.Count '15
            Dim row As New TableRow
            row.ForeColor = Drawing.Color.Blue
            row.Font.Italic = True

            Dim cell1 As New TableCell
            cell1.Text = indx

            Dim cell2 As New TableCell
            cell2.Text = CType(col.Item(indx), Base).Name

            row.Cells.Add(cell1)
            row.Cells.Add(cell2)
            table.Rows.Add(row)

        Next

        If col.Count > summaryHeight Then
            summaryHeight = col.Count
        End If

        cell.Controls.Add(table)

        Return True

    End Function

    Private Function BuildTable2(ByVal tableName As String, ByVal col As Collection, ByVal headerName As String, ByVal cell As TableCell) As Boolean

        Dim table As New Table
        table.GridLines = GridLines.Both
        table.ID = tableName
        Dim headerRow As New TableRow
        headerRow.BackColor = Drawing.Color.Beige
        headerRow.Font.Bold = True
        Dim headerCell As New TableCell
        headerCell.Text = headerName

        headerRow.Cells.Add(headerCell)

        table.Rows.Add(headerRow)

        For indx As Integer = 1 To col.Count '15
            Dim row As New TableRow
            row.ForeColor = Drawing.Color.Blue
            row.Font.Italic = True

            Dim cell1 As New TableCell
            cell1.Text = CType(col.Item(indx), Base).Name

            row.Cells.Add(cell1)
            table.Rows.Add(row)

        Next
        If col.Count > summaryHeight Then
            summaryHeight = col.Count
        End If

        cell.Controls.Add(table)

        Return True

    End Function


    Private Function PopulateInjuries(ByVal eng As PrivateEngine) As Boolean

        injuriesdiv.Controls.Clear()
        Dim table As New Table
        table.GridLines = GridLines.Both

        Dim rowHeader1 As New TableRow
        rowHeader1.HorizontalAlign = HorizontalAlign.Center
        rowHeader1.Font.Bold = True
        rowHeader1.BorderStyle = BorderStyle.Solid
        rowHeader1.BackColor = Drawing.Color.Beige

        Dim cellHeaderA As New TableCell
        cellHeaderA.Text = "Probability of Recovery"
        cellHeaderA.ColumnSpan = 7
        Dim cellHeaderB As New TableCell
        cellHeaderB.Text = "Probability of Getting injured at a certain age"
        cellHeaderB.ColumnSpan = 7

        rowHeader1.Cells.Add(New TableCell)
        rowHeader1.Cells.Add(New TableCell)
        rowHeader1.Cells.Add(New TableCell)
        rowHeader1.Cells.Add(cellHeaderA)
        rowHeader1.Cells.Add(New TableCell)
        rowHeader1.Cells.Add(cellHeaderB)

        Dim rowHeader2 As New TableRow
        rowHeader2.HorizontalAlign = HorizontalAlign.Center
        rowHeader2.Font.Bold = True
        rowHeader2.BackColor = Drawing.Color.Beige

        Dim cellHeader1 As New TableCell
        cellHeader1.Text = "Injury"

        Dim cellHeader2 As New TableCell
        cellHeader2.Text = ""

        Dim cellHeader3 As New TableCell
        cellHeader3.Text = "Ideal Recovery Weeks "

        Dim cellHeader4 As New TableCell
        cellHeader4.Text = "Age<16"

        Dim cellHeader5 As New TableCell
        cellHeader5.Text = "16<=Age<=20"

        Dim cellHeader6 As New TableCell
        cellHeader6.Text = "20<=Age<25"

        Dim cellHeader7 As New TableCell
        cellHeader7.Text = "25<=Age<30"

        Dim cellHeader8 As New TableCell
        cellHeader8.Text = "30<=Age<35"

        Dim cellHeader9 As New TableCell
        cellHeader9.Text = "35<=Age<40"

        Dim cellHeader10 As New TableCell
        cellHeader10.Text = "Age>=40"

        Dim cellHeader11 As New TableCell
        cellHeader11.Text = ""

        Dim cellHeader12 As New TableCell
        cellHeader12.Text = "Age<16"

        Dim cellHeader13 As New TableCell
        cellHeader13.Text = "16<=Age<=20"

        Dim cellHeader14 As New TableCell
        cellHeader14.Text = "20<=Age<25"

        Dim cellHeader15 As New TableCell
        cellHeader15.Text = "25<=Age<30"

        Dim cellHeader16 As New TableCell
        cellHeader16.Text = "30<=Age<35"

        Dim cellHeader17 As New TableCell
        cellHeader17.Text = "35<=Age<40"

        Dim cellHeader18 As New TableCell
        cellHeader18.Text = "Age>=40"

        rowHeader2.Cells.Add(cellHeader1)
        rowHeader2.Cells.Add(cellHeader2)
        rowHeader2.Cells.Add(cellHeader3)
        rowHeader2.Cells.Add(cellHeader4)
        rowHeader2.Cells.Add(cellHeader5)
        rowHeader2.Cells.Add(cellHeader6)
        rowHeader2.Cells.Add(cellHeader7)
        rowHeader2.Cells.Add(cellHeader8)
        rowHeader2.Cells.Add(cellHeader9)
        rowHeader2.Cells.Add(cellHeader10)
        rowHeader2.Cells.Add(cellHeader11)
        rowHeader2.Cells.Add(cellHeader12)
        rowHeader2.Cells.Add(cellHeader13)
        rowHeader2.Cells.Add(cellHeader14)
        rowHeader2.Cells.Add(cellHeader15)
        rowHeader2.Cells.Add(cellHeader16)
        rowHeader2.Cells.Add(cellHeader17)
        rowHeader2.Cells.Add(cellHeader18)

        table.Rows.Add(rowHeader1)
        table.Rows.Add(rowHeader2)

        For Each injury As Base In eng.SelectedInjuriesCol

            Dim row As New TableRow
            row.Font.Italic = True
            row.ForeColor = Drawing.Color.Blue
            Dim cell As TableCell



            Dim injuryId As Integer = injury.ID

            Dim injurySetup As InjurySetup = injury.Setup

            cell = New TableCell
            cell.Text = injury.Name
            row.Cells.Add(cell)

            'blank column
            cell = New TableCell

            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = injurySetup.RecoveryWeeks
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = injurySetup.RecoveryAgeMap.Item(Cons.AGERANGE1)
            row.Cells.Add(cell)
            
            
            cell = New TableCell
            cell.Text = injurySetup.RecoveryAgeMap.Item(Cons.AGERANGE2)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = injurySetup.RecoveryAgeMap.Item(Cons.AGERANGE3)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = injurySetup.RecoveryAgeMap.Item(Cons.AGERANGE4)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = injurySetup.RecoveryAgeMap.Item(Cons.AGERANGE5)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = injurySetup.RecoveryAgeMap.Item(Cons.AGERANGE6)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = injurySetup.RecoveryAgeMap.Item(Cons.AGERANGE7)
            row.Cells.Add(cell)



            cell = New TableCell
            row.Cells.Add(cell)



            cell = New TableCell
            cell.Text = CType(CType(eng.Simulation.Setup, SimulationSetup).InjuriesMap.Item(injuryId), Hashtable).Item(Cons.AGERANGE1)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = CType(CType(eng.Simulation.Setup, SimulationSetup).InjuriesMap.Item(injuryId), Hashtable).Item(Cons.AGERANGE2)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = CType(CType(eng.Simulation.Setup, SimulationSetup).InjuriesMap.Item(injuryId), Hashtable).Item(Cons.AGERANGE3)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = CType(CType(eng.Simulation.Setup, SimulationSetup).InjuriesMap.Item(injuryId), Hashtable).Item(Cons.AGERANGE4)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = CType(CType(eng.Simulation.Setup, SimulationSetup).InjuriesMap.Item(injuryId), Hashtable).Item(Cons.AGERANGE5)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = CType(CType(eng.Simulation.Setup, SimulationSetup).InjuriesMap.Item(injuryId), Hashtable).Item(Cons.AGERANGE6)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = CType(CType(eng.Simulation.Setup, SimulationSetup).InjuriesMap.Item(injuryId), Hashtable).Item(Cons.AGERANGE7)
            row.Cells.Add(cell)


            table.Rows.Add(row)

        Next

        injuriesHeight = eng.SelectedInjuriesCol.Count
        injuriesdiv.Controls.Add(table)

        Return True

    End Function

    Private Function PopulateTrainings(ByVal eng As PrivateEngine) As Boolean

        trainingsdiv.Controls.Clear()

        Dim table As New Table
        table.GridLines = GridLines.Both

        Dim rowHeader1 As New TableRow
        rowHeader1.HorizontalAlign = HorizontalAlign.Center
        rowHeader1.Font.Bold = True
        rowHeader1.BackColor = Drawing.Color.Beige

        Dim cellHeader As TableCell

        cellHeader = New TableCell
        cellHeader.Text = "Training"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Ideal Growth"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Age<16"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "16<=Age<=20"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "20<=Age<25"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "25<=Age<30"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "30<=Age<35"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "35<=Age<40"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Age>=40"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Attribute/Category"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Position/Zones"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "GK"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "SW"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RB"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RWB"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RCB"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "CB"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LCB"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LWB"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LB"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RAM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RCM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RDM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "CM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "CAM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "CDM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LDM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LCM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LAM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LM"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RW"
        rowHeader1.Cells.Add(cellHeader)


        cellHeader = New TableCell
        cellHeader.Text = "RF"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "RS"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "CF"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "ST"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LS"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LF"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "LW"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Keepers"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Defenders"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Midfielders"
        rowHeader1.Cells.Add(cellHeader)

        cellHeader = New TableCell
        cellHeader.Text = "Forwards"
        rowHeader1.Cells.Add(cellHeader)



        table.Rows.Add(rowHeader1)

        For Each training As Base In eng.SelectedTrainingsCol
            Dim row As New TableRow
            row.Font.Italic = True
            row.ForeColor = Drawing.Color.Blue
            Dim cell As TableCell

           


            Dim trainingSetup As TrainingSetup = training.Setup

            cell = New TableCell
            cell.Text = training.Name
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.PointsForFUllTraining
            row.Cells.Add(cell)


           
            cell = New TableCell
            cell.Text = trainingSetup.TrainingAgeMap.Item(Cons.AGERANGE1)
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.TrainingAgeMap.Item(Cons.AGERANGE2)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.TrainingAgeMap.Item(Cons.AGERANGE3)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.TrainingAgeMap.Item(Cons.AGERANGE4)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.TrainingAgeMap.Item(Cons.AGERANGE5)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.TrainingAgeMap.Item(Cons.AGERANGE6)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.TrainingAgeMap.Item(Cons.AGERANGE7)
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.TrainingType & "(" & trainingSetup.TrainingTypeSelected & ")"
            row.Cells.Add(cell)



            cell = New TableCell
            cell.Text = trainingSetup.TrainingAffecting
            row.Cells.Add(cell)
           

            cell = New TableCell
            cell.Text = trainingSetup.GK
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.SW
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RB
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RWB
            row.Cells.Add(cell)


            cell = New TableCell
            cell.Text = trainingSetup.RCB
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.CB
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LCB
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LWB
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LB
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RAM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RCM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RDM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.CM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.CAM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.CDM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LDM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LCM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LAM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LM
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RW
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RF
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.RS
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.CF
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.ST
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LS
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.LW
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.Keeper
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.Defense
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.Midfield
            row.Cells.Add(cell)

            cell = New TableCell
            cell.Text = trainingSetup.Forward
            row.Cells.Add(cell)

            table.Rows.Add(row)
        Next

        trainingsHeight = eng.SelectedTrainingsCol.Count
        trainingsdiv.Controls.Add(table)

        Return True

    End Function

    Private Function PopulatePlayers(ByVal eng As PrivateEngine) As Boolean

        Dim table As Table
        Dim row As TableRow
        Dim cell As TableCell

        For season As Integer = 1 To Cons.MAX_SEASONS
            Page.FindControl("season" & season & "div").Controls.Clear()

            table = New Table()
            table.GridLines = GridLines.Both

            table.Rows.Add(New TableRow)

            For Each player As Base In eng.SelectedPlayersCol


                Dim setup As PlayerSetup = player.Setup

                row = New TableRow
                row.Font.Bold = True

                cell = New TableCell
                cell.Text = "ID"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = player.ID
                row.Cells.Add(cell)

                table.Rows.Add(row)

                row = New TableRow
                row.Font.Bold = True

                cell = New TableCell
                cell.Text = "Name"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = player.Name
                row.Cells.Add(cell)

                table.Rows.Add(row)


                row = New TableRow
                row.Font.Bold = True

                cell = New TableCell
                cell.Text = "Position"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = setup.Position
                row.Cells.Add(cell)

                table.Rows.Add(row)


                row = New TableRow
                row.Font.Bold = True

                cell = New TableCell
                cell.Text = ""
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Overall"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Status"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Age"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Training"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Probability of Injury"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Injury Type"
                row.Cells.Add(cell)


                cell = New TableCell
                cell.Text = "Recovery Left"
                row.Cells.Add(cell)


                cell = New TableCell
                cell.Text = "Crossing"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Finishing"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Heading"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Short Pass"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Volleys"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Shot Power"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Jumping"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Stamina"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Strength"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Long Shot"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Aggression"
                row.Cells.Add(cell)


                cell = New TableCell
                cell.Text = "Tact. Aware."
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Positioning"
                row.Cells.Add(cell)


                cell = New TableCell
                cell.Text = "Vision"
                row.Cells.Add(cell)


                cell = New TableCell
                cell.Text = "Penalties"
                row.Cells.Add(cell)


                ''''
                cell = New TableCell
                cell.Text = "Curve"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Dribbling"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Freekick"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Long Pass"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Ball Control"
                row.Cells.Add(cell)

                ''''
                cell = New TableCell
                cell.Text = "Acceleration"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Agility"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Sprint"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Balance"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Reactions"
                row.Cells.Add(cell)


                ''''
                cell = New TableCell
                cell.Text = "Marking"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Slide Tackle"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Stand Tackle"
                row.Cells.Add(cell)

                ''''
                cell = New TableCell
                cell.Text = "Diving"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Handling"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Kicking"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "One On One"
                row.Cells.Add(cell)

                cell = New TableCell
                cell.Text = "Reflexes"
                row.Cells.Add(cell)

                table.Rows.Add(row)

                table.Rows.Add(New TableRow()) 'blank row
                Dim lastSnapSetup As PlayerSetup = Nothing

                For week As Integer = 1 To Cons.MAX_WEEKS
                    Dim val As Double = 0.0
                    Dim valStr As String = ""
                    Dim key As Lookup = Utility.GetKey(season, week, player)

                    Dim snap As Base = eng.SnapShotData.Item(key)
                    Dim snapSetup As PlayerSetup = snap.Setup

                    row = New TableRow
                    row.Font.Italic = True
                    row.ForeColor = Drawing.Color.Blue

                    cell = New TableCell
                    cell.Font.Italic = False
                    cell.Font.Bold = True
                    cell.ForeColor = Drawing.Color.Black
                    cell.Text = "Week" & week
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Overall
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Overall <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)



                    cell = New TableCell
                    valStr = snapSetup.Status
                    If (Not lastSnapSetup Is Nothing) Then
                        If Not lastSnapSetup.Status.Equals(valStr) Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = valStr
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.Age
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Age <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)




                    cell = New TableCell
                    cell.Text = Utility.GetBase(eng.SelectedTrainingsCol, CType(eng.Simulation.Setup, SimulationSetup).TrainingMap.Item("Season" & season)).Name
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.ProbabiltyOfInjury
                    If (Not lastSnapSetup Is Nothing) Then
                        If Not lastSnapSetup.ProbabiltyOfInjury = val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    cell = New TableCell
                    valStr = snapSetup.InjuryType
                    If (Not lastSnapSetup Is Nothing) Then
                        If Not lastSnapSetup.InjuryType.Equals(valStr) Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = valStr
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.RecoveryLeft
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.RecoveryLeft <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)




                    cell = New TableCell
                    val = snapSetup.Crossing
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Crossing <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Finishing
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Finishing <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Heading
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Heading <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Short_pass
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Short_pass <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.Volleys
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Volleys <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)



                    cell = New TableCell
                    val = snapSetup.Shot_power
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Shot_power <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)



                    cell = New TableCell
                    val = snapSetup.Jumping
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Jumping <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.Stamina
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Stamina <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)



                    cell = New TableCell
                    val = snapSetup.Strength
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Strength <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Long_shot
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Long_shot <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    ''''

                    cell = New TableCell
                    val = snapSetup.Aggression
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Aggression <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)



                    cell = New TableCell
                    val = snapSetup.Tactical_awareness
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Tactical_awareness <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Positioning
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Positioning <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.Vision
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Vision <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.Penalties
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Penalties <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    ''''

                    cell = New TableCell
                    val = snapSetup.Curve
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Curve <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Dribbling
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Dribbling <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Freekick
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Freekick <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Long_pass
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Long_pass <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.BallControl
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.BallControl <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    ''''
                    cell = New TableCell
                    val = snapSetup.Acceleration
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Acceleration <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Agility
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Agility <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Sprint
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Sprint <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Balance
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Balance <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Reactions
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Reactions <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    ''''
                    cell = New TableCell
                    val = snapSetup.Marking
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Marking <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.Slide_tackle
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Slide_tackle <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Standing_tackle
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Standing_tackle <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    ''''

                    cell = New TableCell
                    val = snapSetup.Diving
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Diving <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Handling
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Handling <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    cell = New TableCell
                    val = snapSetup.Kicking
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Kicking <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.One_on_one
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.One_on_one <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)

                    cell = New TableCell
                    val = snapSetup.Reflexes
                    If (Not lastSnapSetup Is Nothing) Then
                        If lastSnapSetup.Reflexes <> val Then
                            cell.ForeColor = Drawing.Color.Red
                        End If
                    End If
                    cell.Text = val
                    row.Cells.Add(cell)


                    table.Rows.Add(row)


                    lastSnapSetup = snapSetup.Clone
                Next

                table.Rows.Add(New TableRow)
            Next

            'season1div.Controls.Add(table)
            Page.FindControl("season" & season & "div").Controls.Add(table)
            seasonsHeight = eng.SelectedPlayersCol.Count
        Next



    End Function

    Protected Function CalcSummaryHeight() As Integer

        Return summaryHeight * 40
    End Function

    Protected Function CalcInjuriesHeight() As Integer

        Return injuriesHeight * 50
    End Function

    Protected Function CalcTrainingsHeight() As Integer

        Return trainingsHeight * 50
    End Function

    Protected Function CalcPlayersHeight() As Integer

        Return 15 * seasonsHeight * 1200

    End Function

    Protected Function CalcSeasonsHeight() As Integer

        Return seasonsHeight * 1200

    End Function

    Protected Function CalcSeasonWidth() As Integer
        Return 2400
    End Function


End Class
